#include "CTween.h"

Int32 CALLBACKTYPE GetQuadraticValue(
    /* [in] */ Int32 fromValue,
    /* [in] */ Int32 toValue,
    /* [in] */ Millisecond32 elaspedTime,
    /* [in] */ Millisecond32 durationTime,
    /* [in] */ EaseType easeType)
{
    Int64 dx = ((Int64)(toValue - fromValue)) << VALUE_FICTION;
    Int64 delta = 0;
    Int64 t = elaspedTime;
    Int64 d = durationTime;

    switch (easeType) {
        case EaseType_In:
        delta = dx * t * t / (d * d);
        break;

        case EaseType_Out:
        delta = dx * ((d << 1) - t) * t / (d * d);
        break;

        case EaseType_InOut:
        if ((t << 1) < d) {
            delta = (dx * t * t << 1) / (d * d);
        }
        else {
            delta = dx * ((d * t << 2) - (t * t << 1) - d * d) / (d * d);
        }
        break;

        default:
            assert(0);
    }

    return fromValue + (Int32)(delta >> VALUE_FICTION);
}
